package main

import "fmt"

type Stack[T any] []T

func (s *Stack[T]) Push(elem T) {
	*s = append(*s, elem)
}

func (s *Stack[T]) Pop() (res *T) {
	if len(*s) > 0 {
		res = &(*s)[len(*s)-1]
		*s = (*s)[:len(*s)-1]
	}
	return
}

func (s *Stack[T]) Top() *T {
	if len(*s) > 0 {
		return &(*s)[len(*s)-1]
	}
	return nil
}

func (s *Stack[T]) Len() int {
	return len(*s)
}

func (s *Stack[T]) Print() {
	for _, elem := range *s {
		fmt.Print(elem)
		fmt.Print(" ")
	}
	fmt.Println("")
}

func main() {
	s := Stack[int]{}
	for i := 0; i < 100; i += 12 {
		s.Push(i)
	}
	s.Print()
	for n := s.Pop(); n != nil; n = s.Pop() {
		fmt.Println(*n)
	}
}
